unit WbExecutiveFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, WbNode_TLB, ExtCtrls, ComServ;

type
  TWbExecutiveForm = class(TForm)
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure WMCopyData(var Msg : TWMCopyData) ; message WM_COPYDATA;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  WbExecutiveForm: TWbExecutiveForm;
  INodeArray:array[0..1000] of IWbNodeClass;
  INodeSnArray:array[0..1000] of Integer;
  SN:Integer;
  INodeArrayCount:Integer;

implementation

{$R *.dfm}

procedure DisplayMessage(Text: String; title: String);
begin
  MessageBox(0, PChar(Text), PChar(title), MB_ICONEXCLAMATION);
end;

procedure TWbExecutiveForm.FormCreate(Sender: TObject);
begin
//http://blog.delphi-jedi.net/2008/07/01/com-server-tells-you-sth-about-opened-client-connections/
ComServer.UIInteractive := false;

INodeArrayCount := 0;
SN := 0;
Timer1.Enabled := true;
end;

procedure TWbExecutiveForm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := false;
//DisplayMessage('TWbExecutiveForm.Timer1Timer','');
INodeArrayCount := INodeArrayCount + 1;
SN := SN + 1;
INodeArray[INodeArrayCount-1] := CoWbNodeClass.Create;
INodeSnArray[INodeArrayCount-1] := SN;
end;


procedure TWbExecutiveForm.WMCopyData(var Msg: TWMCopyData) ;
var
s : string;
sl:TStringList;
NodeSnToDelete:Integer;
i,index:Integer;
begin
s := PChar(Msg.CopyDataStruct.lpData) ;
sl := TStringList.Create;
sl.Text := s;//forgot this!
if sl.Strings[0]='DeleteWbNodeBySN' then
begin
  NodeSnToDelete := StrToInt(sl.Strings[1]);
  //DisplayMessage('DeleteWbNodeBySN - NodeSnToDelete='+IntToStr(NodeSnToDelete),'');
  index := -1;
  for i := 0 to INodeArrayCount - 1 do
    if INodeSnArray[i] = NodeSnToDelete then
      index := i;
  //DisplayMessage('DeleteWbNodeBySN - index='+IntToStr(index),'');
  if index<>-1 then
  begin
    INodeArray[index] := nil;
    INodeSnArray[index] := -1;
    for i := index to INodeArrayCount - 1 - 1 do
    begin
      INodeArray[i] := INodeArray[i+1];
      INodeSnArray[i] := INodeSnArray[i+1];
    end;
    INodeArrayCount := INodeArrayCount - 1;
  end;
end;
sl.Free
end;

end.
